package client.comm.baoding.ui

import client.comm.commlib.base.BaseActivity
import client.comm.baoding.R
import client.comm.baoding.databinding.ActivityTestBinding
import client.comm.baoding.ui.vm.TestViewModel
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.SimpleExoPlayer

class TestActivity : BaseActivity<TestViewModel, ActivityTestBinding>() {
    override fun getLayout(): Int {
        return R.layout.activity_test
    }

    override fun initView() {

        initPlayer()
    }

    val player by lazy {
        SimpleExoPlayer.Builder(this)
            .build()
    }

    fun initPlayer() {
        binding.playerView.player = player

        //填充播放列表
        val mediaItem =
            MediaItem.fromUri("http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400")
        player.addMediaItem(mediaItem)
        player.prepare()
        player.play()
    }

    override fun initViewModel(): TestViewModel = createViewModel()

    override fun onResume() {
        super.onResume()
        player.play()
    }

    override fun onPause() {
        super.onPause()
        player.pause()
    }

    override fun onDestroy() {
        super.onDestroy()
        player.release()
    }

    fun change(){

    }
}